﻿using System;
using System.Collections.Generic;
using System.Data;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.Utility;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite
{
    public partial class Index : WebSiteBaseicPage
    {
        private readonly AdbannerBLL _adbannerBll = new AdbannerBLL();

        private readonly ProductBLL _productBll = new ProductBLL();

        private readonly NewsBLL _newsBll = new NewsBLL();

        protected DataTable AdbannerList { get; set; }

        protected DataTable ProductList { get; set; }

        protected NewsInfo NewInfo1 { get; set; }

        protected NewsInfo NewInfo2 { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            InitializationData();
        }

        public void InitializationData()
        {
            AdbannerList = _adbannerBll.GetAdbannerList();
            ProductList = _productBll.GetProductList();
            var ds = _newsBll.GetModel();
            if (ds != null && ds.Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Rows)
                {
                    switch (dr["NewTypeId"].ToString())
                    {
                        case "2":
                            NewInfo1=new NewsInfo
                                         {
                                             NewId = int.Parse(dr["NewId"].ToString()),
                                             NewTitle = dr["NewTitle"].ToString(),
                                             NewTypeId = int.Parse(dr["NewTypeId"].ToString())
                                         };
                            var content1 = dr["NewContent"].ToString();
                            {
                                var strContent = StringPlus.DropHTML(content1);
                                if (strContent.Length > 200)
                                {
                                    NewInfo1.NewContent = strContent.Substring(0, 200) + "...";
                                }
                                else
                                {
                                    NewInfo1.NewContent = strContent;
                                }
                            }
                            break;
                        case "3":
                            NewInfo2=new NewsInfo
                                         {
                                             NewId = int.Parse(dr["NewId"].ToString()),
                                             NewTitle = dr["NewTitle"].ToString(),
                                             NewTypeId = int.Parse(dr["NewTypeId"].ToString())
                                         };
                            var content2 = dr["NewContent"].ToString();
                            {
                                var strContent = StringPlus.DropHTML(content2);
                                if (strContent.Length > 100)
                                {
                                    NewInfo2.NewContent = strContent.Substring(0, 100) + "...";
                                }
                                else
                                {
                                    NewInfo2.NewContent = strContent;
                                }
                            }
                            break;
                    }
                }
            }
            
        }
    }
}